package com.rjyb.dyxz.dao.Impl;

import com.rjyb.dyxz.dao.IUserDao;
import com.rjyb.dyxz.pojo.User;
import com.rjyb.dyxz.unit.DB;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoImpl implements IUserDao {
    private final QueryRunner runner = new QueryRunner();
    private User user= new User();
    @Override
    public boolean CheckForPlagiarism(String userName) {
        try {
            user = runner.query(DB.getConnection(),"select userName from s_user where userName = ?",new BeanHandler<User>(User.class),userName);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user == null;
    }

    @Override
    public void enroll(User user) {
        try {
            runner.update(DB.getConnection(),"insert into s_user (userName, userPwd, name, sex, age, phone, email, address,regTime,logTime)values (?,?,?,?,?,?,?,?,?,?)",user.getUserName(),user.getUserPwd(),user.getName(),user.getSex(),user.getAge(),user.getPhone(),user.getEmail(),user.getAddress(),user.getReqTime(),user.getLogTime());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean phoneNumber(String phone) {
        try {
            user = runner.query(DB.getConnection(),"select userName from s_user where userName = ?",new BeanHandler<User>(User.class),phone);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return user == null;
    }
    //这路写mysql语句
}
